<?php

declare(strict_types=1);

namespace app\common\controller;

use app\common\common\BaseController;
use app\common\model\Horse as HorseModel;
use app\common\model\HorseBreedingParameters as HorseBreedingParametersModel;
use app\common\model\HorseBreedingPic as HorseBreedingPicModel;
use app\common\model\HorseParameters as HorseParametersModel;
use app\common\model\HorsePic as HorsePicModel;
use app\common\model\HorseBreeding as HorseBreedingModel;
use app\common\services\OSS;
use think\Image;

/**
 * @xk 公共ajax方法
 */
class Ajax extends BaseController
{
    public function  uploadUrl($dir_name='static/common/images/') {
      $oss = new OSS();
      $result = false;
      if(is_dir($dir_name)){
        if ($handle = opendir($dir_name)) {
          while (false !== ($item = readdir($handle))) {
            if ($item != '.' && $item != '..') {
              if (is_dir($dir_name . '/' . $item)) {
                $this->uploadUrl($dir_name . '/' . $item);
              } else {
                $newarray = explode(".",$dir_name.'/'.$item);
                $type = $newarray[count($newarray)-1];
                $lastpass = $dir_name . '/' . $item;
                $tmp = tempnam(sys_get_temp_dir(), $newarray[0]);
                $oss->fileUpload($lastpass,$tmp);
                die($tmp);
              }
            }
          }
          closedir($handle);
        }
      }
    }
}
